package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

@Getter
public enum ClueAutoDistributTypeEnum {
    /**
     * 仅分配
     */
    ONLY_ASSIGNED(0, "enum.clueAutoDistributType.name.only_assigned"),
    /**
     * 循环分配
     */
    CIRCULATION_DISTRIBUTION(1, "enum.clueAutoDistributType.name.circulation_distribution"),
    /**
     * 按比例分配
     */
    PROPORTIONAL_ALLOCATION(2, "enum.clueAutoDistributType.name.proportional_allocation"),
    /**
     * 按数量分配
     */
    NUMBER_ASSIGNED(3, "enum.clueAutoDistributType.name.number_assigned"),
    ;

    private Integer type;
    private String name;
    ClueAutoDistributTypeEnum(Integer type, String name) {
        this.type = type;
        this.name = name;
    }

    /**
     * 通过枚举<code>code</code>获得枚举
     *
     * @param code 枚举值
     * @return PublicCustomerRuleEnum
     */
    public static ClueAutoDistributTypeEnum getByCode(Integer type) {
        for (ClueAutoDistributTypeEnum cacheCode : values()) {
            if (type.equals(cacheCode.getType())) {
                return cacheCode;
            }
        }
        return null;
    }

    public static String getNameByCode(Integer type) {
        for (ClueAutoDistributTypeEnum cacheCode : values()) {
            if (type.equals(cacheCode.getType())) {
                return cacheCode.getName();
            }
        }
        return "";
    }

    public String getName() {
        return I18nMessageUtil.getMessage(name);
    }

}
